/**
 * 星座的controller层
 * @name: star.controller
 * @data: 2024/5/29 11:15
 */
import {Controller, Get, Inject, Param} from "@midwayjs/core";
import {Context} from "@midwayjs/koa";
import Result from "../common/Result";
import User from "../pojo/entity/user.entity";
import {HTTP_STATE_CODE} from "../common/const";
import {TarotBigCardService} from "../service/tarotBigCard.service";
import TarotBigCard from "../pojo/entity/tarotBigCard.entity";
import ResultInterface from "../interface/Result";

@Controller("/tarotbigcard")
export class TarotBigCardController {
  @Inject()
  tarotBigCardService:TarotBigCardService;
  @Inject()
  ctx: Context;


  /**
   * 获取全部卡牌列表,无分页
   */
  @Get("/select")
  async selectStarAll(){
    try {
      const result=await this.tarotBigCardService.selectAllTarotBigCard();
      if (result.length>0){
        return Result<TarotBigCard>({
          code: HTTP_STATE_CODE.SUCCESS,
          msg: "查询成功",
          data: result,
        });
      }else {
        return Result<User>({
          code: HTTP_STATE_CODE.NO_CONTENT,
          msg: "列表为空",
        });
      }
    }catch (e) {
      console.log(42, e);
    }
  }


  /**
   * @description 根据name模糊查询星座列表
   * @param name
   */
  @Get("/name/:name")
  async selectTarotBigCardByName(@Param("name") name:string):Promise<ResultInterface<TarotBigCard>>{
    try {
      const result=await this.tarotBigCardService.selectTarotBigCardByName(name);
      if (result.length>0) {
        return Result<TarotBigCard>({
          code: HTTP_STATE_CODE.SUCCESS,
          msg: "查询成功",
          data: result
        });
      }else{
        return Result<any>({
          code: HTTP_STATE_CODE.NO_CONTENT,
          msg: "查询失败",
        });
      }
    }catch (e) {
      return Result<any>({
        code: HTTP_STATE_CODE.ERROR,
        msg: "查询失败",
        data: e
      });
    }
  }

  /**
   * @description 根据name模糊查询星座列表
   * @param name
   */
  @Get("/:tarotBigCardId")
  async selectTarotBigCardById(@Param("tarotBigCardId") tarotBigCardId:number):Promise<ResultInterface<TarotBigCard>>{
    try {
      const result=await this.tarotBigCardService.selectTarotBigCardById(tarotBigCardId);
      if (result) {
        return Result<TarotBigCard>({
          code: HTTP_STATE_CODE.SUCCESS,
          msg: "查询成功",
          data: result
        });
      }else{
        return Result<any>({
          code: HTTP_STATE_CODE.NO_CONTENT,
          msg: "查询失败",
        });
      }
    }catch (e) {
      return Result<any>({
        code: HTTP_STATE_CODE.ERROR,
        msg: "查询失败",
        data: e
      });
    }
  }

}
